<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    okText="确认添加"
    cancelText="取消">

    <div>

      <div>
        <span>商品编号</span>
        <a-input placeholder="请输入商品编号" style="color: #5f5e5e;font-weight: bold;width: 160px;margin-left: 5px" v-model="goods_code"></a-input>
        <span style="margin-left: 10px">供应商商品编号</span>
        <a-input placeholder="请输入供应商商品编号" style="color: #5f5e5e;font-weight: bold;width: 160px;margin-left: 5px" v-model="supplierGoodsCode"></a-input>
        <a-button type="primary" @click="showgoods_list" style="color: #F9D532;width: 80px;height: 32px;background: #333333;border-style: none;font-size: 12px;margin-left: 10px">搜索</a-button>
        <a-button @click="reset_data" style="color: #333333;width: 80px;height: 32px;background: #dcdada;border-style: none;font-size: 12px;margin-left: 10px">重置</a-button>
      </div>

      <div style="margin-bottom: 10px;border: none;background-color: #ffffff;margin-top: 10px">
        <span style="color: #2d2d2d;font-size: 14px;font-weight: bolder">商品列表</span>
      </div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
        >

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.goodsMainImg)" icon="img"/>
          </div>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
         <input type="radio" name="redio" id="radioMoneyPriority" @click="get_goodsId(record)">
        </span>
      </a-table>
    </div>

    <div>
      <span>入库数量：</span>
      <a-input placeholder="请输入商品入库数量" style="color: #5f5e5e;font-weight: bold;width: 160px;margin-left: 5px" v-model="instorage_count"></a-input><br/>
      <span style="margin-top: 10px">入库金额：</span>
      <a-input placeholder="请输入入库金额" style="color: #5f5e5e;font-weight: bold;width: 160px;margin-left: 5px;margin-top: 10px" v-model="instorage_money"></a-input><br/>
      <span style="margin-top: 10px">结算方式：</span>
      <a-select v-model="select_status" style="color: #827d7d;margin-top: 10px;margin-left: 5px;width: 160px;" placeholder="请选择计算方式">
        <a-select-option :value="item.id" v-for="item in statuslist" >{{ item.name }}</a-select-option>
      </a-select>
    </div>


  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import '@/assets/less/TableExpand.less'
  import { deleteAction, getAction,putAction,postAction,downFile,getFileAccessHttpUrl } from '@/api/manage'

  export default {
    name: "LgyxPostingRequirementsModal",
    mixins:[JeecgListMixin],
    components: {
    },
    data () {
      return {
        ipagination:{
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        select_goodid:'',//选中的商品id
        select_isfabric:'',//是否是面料
        goods_code:'',
        supplierGoodsCode:'',
        instorage_count:'',//入库数量
        instorage_money:'',//入库单价
        select_status:'请选择结算方式',
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        companys:'',
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        statuslist: [
          {
            id: '0',
            name: '备库'
          },
          {
            id: '1',
            name: '代售'
          },
          {
            id: '2',
            name: '寄售'
          }
        ],
        confirmLoading: false,
        validatorRules: {},
        // 表头
        columns: [
          {
            title: '请选择',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          },
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title: '缩略图',
            align: "center",
            width: 150,
            dataIndex: 'goodsMainImg',
            scopedSlots: {customRender: "avatarslot"}
          },
          {
            title:'商品编号',
            align:"center",
            dataIndex: 'goodsCode'
          },
          {
            title:'供应商商品编号',
            align:"center",
            dataIndex: 'supplierGoodsCode'
          },
          {
            title:'类型',
            align:"center",
            dataIndex: 'goodsTypeName'
          },
          {
            title:'单位',
            align:"center",
            dataIndex: 'unit'
          }
        ],
        url: {
          list: "/inventory/manger/goods_fabricPagelist",
          submit_ruku_goods: "/inventory/manger//add_instorageDan_goods",
          deleteBatch: "/companymanger/lgyxCompanymanger/deleteBatch",
          exportXlsUrl: "/companymanger/lgyxCompanymanger/exportXls",
          importExcelUrl: "companymanger/lgyxCompanymanger/importExcel"
        },
        dictOptions:{},
      }
    },
    created () {
      // this.showcompany_list_checked();
    },
    methods: {
      showcompany_list() {
        getAction(this.url.list).then((res)=>{
          if(res.success){
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
            this.
            this.url.list="/inventory/manger/goods_fabricPagelist";
          }else {
            // this.$message.error("查询失败");
          }
        });
      },
      get_goodsId(recorod){//触发列表拿值
        // alert(recorod.type+"=="+recorod.hybridId)
        this.select_goodid = recorod.id;
        this.select_isfabric = recorod.isGood;
      },
      reset_data(){//重置
        this.goods_code='';
        this.supplierGoodsCode='';
        this.showgoods_list();
      },
      showgoods_list() {
        let params = {
          pageNo:1,
          pageSize:10,
          goods_code:this.goods_code,
          supplierGoodsCode:this.supplierGoodsCode
        };
        getAction(this.url.list,params).then((res)=>{
          if(res.success){
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          }else {
            // this.$message.error("查询失败");
          }
        });
      },
      getAvatarView: function (avatar) {
        return getFileAccessHttpUrl(avatar)
      },
      add () {
        this.edit({});
      },
      edit (record) {
        this.select_goodid = '';
        this.select_isfabric = '';
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.showcompany_list();
      },
      handleOk () {
        if(this.select_goodid==null || this.select_goodid==''){
           this.$message.warning("请选择商品")
           return
        }else if(this.instorage_count==null || this.instorage_count==''){
          this.$message.warning("请输入入库数量")
          return
        }else if(this.instorage_money==null || this.instorage_money==''){
          this.$message.warning("请输入入库单价")
          return
        }else if(this.select_status==null || this.select_status=='请选择结算方式'){
          this.$message.warning("请选择结算方式")
          return
        }else {
          let params = {instorageDanId:this.$route.query.rukudan_id,
            goodsId:this.select_goodid,
            intoSumnumber:this.instorage_count,
            intoUnit:this.instorage_money,
            settlementMethod:this.select_status,
            isFabric:this.select_isfabric
          };
          httpAction(this.url.submit_ruku_goods,params,"post").then((res)=>{
            if(res.success){
              this.$message.success(res.message);
              this.$emit('ok');
              this.close();
            }else {
              this.$message.error(res.message);
            }
          });
        }
      },
      handleCancel () {
        this.close()
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
    }
  }
</script>